<template>
    <div>
     <a href="/qyadd">权益添加</a>
     <tr></tr>
     <a href="/djxs">等级表</a>
     <tr></tr>
     <a href="/hyxs">会员表</a>

        <table class="table">
            <thead>
                <tr>
             
                    <td>权益名称</td>
                    <td>权益状态</td>
                    <td>操作</td>
                </tr>
            </thead>
            <tbody>
                <tr v-for="m in data">
                    <td>{{m.qymc}}</td>
                    <td>{{m.qyzt?"启用":"禁用"}}</td>
                    <td>
                        <input type="button"  value="修改" @click="xg(m.qyid)">
                        <input type="button"   value="修改状态" @click="jiny(m.qyid)">
                        <input type="button"   value="删除" @click="sc(m.qyid)">
                 

                    </td>
                </tr>
            </tbody>
        </table>


        
    </div>
</template>

<script setup lang="ts">
import axios from 'axios';
import { ref,onMounted } from 'vue';
import { useRouter } from 'vue-router';

const stro=useRouter();

const data=ref([{
    "qyid": 0,
  "qymc": "string",
  "qyzt": true
}])
 




onMounted(()=>{
    add();
})
 const add=()=>{
    axios.get("https://localhost:7267/api/qy/hyxs").then(res=>{
        data.value=res.data
    })
 }
 const jiny=(a:any)=>{
    if(!confirm("确认修改状态吗")){
        return
    }
    axios.get("https://localhost:7267/api/qy/xg",{params:{id:a}}).then(res=>{
        if(res.data>0){
            alert("修改成功");
            add();
        }else{
            alert("修改失败")
        }
    })
 }
 const xg=(a:any)=>{
    if(!confirm("确认修改吗")){
        return
    }
    stro.push({path:"/qyxg",query:{qyid:a}})
}
const sc=(a:any)=>{
    if(!confirm("确认删除吗")){
        return
    }
    debugger
    axios.delete("https://localhost:7267/api/qy/dele",{params:{id:a}}).then(res=>{
        if(res.data>0){
            alert("删除成功");
            add();
        }else{
            alert("删除失败")
        }
    })
 }

</script>

<style scoped>

</style>